<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>金字塔层数：<input id="number" type="text"></p>
<div id="three"></div>
<script>
    var str="<p>"
    var level=prompt("输入几层金字塔");
    r=parseFloat(level)&&Number(level)
    if(!isNaN(level)){
        for(var i=1;i<=level;i++){
            for(var j=1;j<=level-i;j++){
                str+="&nbsp&nbsp";
            }
            for(var j=1;j<=2*i-1;j++){
                str+="*";
            }
            str+="<br>";
        }
    }
    str+="</p>"
    document.getElementById("number").value=level;
    document.getElementById("three").innerHTML=str;
</script>
<a href="../第二章.html">返回第二章</a>
</body>
</html>